
<?php
class ZhidaAction extends UserAction{
    public $token;
    public function _initialize(){
        parent::_initialize();
        /*
        if(C('server_key')!==md5(C('server_topdomain').'qq507642401')){
            echo base64_decode('5o6I5p2D5L+h5oGv6ZSZ6K+v77yB6K+36IGU57O75LqR5b6uQ01T5a6Y5pa55oqA5pyvUVE6NTA3NjQyNDAx6I635Y+W5o6I5p2D5a+G6ZKlIQ==');
            die;
        }
        */
        $this->token=$this->_session('token');
        $this->assign('token',$this->token);
        $this->canUseFunction('Zhida');
    }

    public function index(){
        $db = M('Zhida');
        if(IS_POST){
            //$_POST['code'] = $this->_post('code');
            $_POST['token'] = $this->token;
            if(stripos($_POST['code'],'eval') === false && stripos($_POST['code'],'alert') === false && stripos($_POST['code'],'php') === false){
                $_POST['code'] = base64_encode($_POST['code']);
                if($db->where(array('token'=>$this->token))->getField('id')){
                    if($db->where(array('token'=>$this->token))->save($_POST)){
                        $this->success('保存成功');
                    }else{
                        $this->error('保存失败');
                    }
                }else{
                    if($db->create() !== false){
                        if($db->add()){
                            $this->success('保存成功');
                        }else{
                            $this->error('保存失败');
                        }
                    }else{

                        $this->error('发生了点小问题，请稍后再试');
                    }
                }
            }else{
                $this->error('抱歉，代码存在不安全因素，请检查后再试');
            }

        }else{
            $info = $db->where(array('token'=>$this->token))->find();
            $info['code'] = htmlspecialchars_decode(base64_decode($info['code']));
            $this->assign('info',$info);
            $this->display();
        }
    }



}
?>